package cn.itcast.service.company.impl;

import cn.itcast.dao.company.CompanyDao;
import cn.itcast.domain.company.Company;
import cn.itcast.service.company.CompanyService;
import cn.itcast.vo.PageBean;
import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class CompanyServiceImpl implements CompanyService {
    @Autowired
    private CompanyDao companyDao;

    @Override
    public List<Company> findAll() {
        return companyDao.findAll();
    }

    @Override
    public void save(Company company) {
        companyDao.save(company);
    }

    @Override
    public Company findById(String id) {
        return companyDao.findById(id);
    }

    @Override
    public void update(Company company) {
        companyDao.update(company);
    }

    @Override
    public void deleteById(String id) {
        companyDao.deleteById(id);
    }

    @Override
    public PageInfo<Company> findByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Company> list = companyDao.findAll();
        return new PageInfo<Company>(list,5);
    }

    @Override
    public List<String> findModulesByCompanyId(String companyId) {
        return   companyDao.findModuleLisByCompanyId( companyId);

    }

    @Override
    public void updateCompanyModule(String companyId, String moduleIds) {
        companyDao.deleteCompanyAndModuleByCompanyId(companyId);
        if(StringUtils.isNotEmpty(moduleIds)){
            String[] mIds = moduleIds.split(",");
            for (String mId : mIds) {
                companyDao.saveCompanyAndModule(companyId, mId);
            }}
    }

  /*  @Override
    public PageBean findPage(int pageNum, int pageSize) {
//   当前页的数据 select * from ss_company limit (pageNum-1)*pageSize,pageSize
       List<Company> list=companyDao.findPage((pageNum-1)*pageSize,pageSize);
//         总条数：select count(0) from ss_company
        Long total=companyDao.findCount();
        return new PageBean(pageNum,pageSize,list,total);
    }*/

}
